package com.time.hellotime.base;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;

/**
 * ViewHolder的基类
 * Created by Bing on 2016/8/23.
 * E-mail is tx16bing@163.com
 */
public class BaseViewHolder extends RecyclerView.ViewHolder{

    //SparseArray 替代 HashMap进行性能优化
    private SparseArray<View> views = new SparseArray<View>();

    public BaseViewHolder(View itemView) {
        super(itemView);
    }

    public <E extends View> E getView(int resId) {
        View v = views.get(resId);
        if (null == v) {
            v = itemView.findViewById(resId);
            views.put(resId, v);
        }
        return (E) v;
    }
}
